#-*- coding: utf-8 -*-

import simpleform as sf


class CommentForm(sf.Form):
	author = sf.Field(label='你的称呼', widget=sf.TextWidget(attrs={'size':16}),
		help_text = '* 必填')
	email = sf.Field(label='电子邮件', widget=sf.TextWidget(attrs={'size':30}),
		help_text = '* 必填')
	url = sf.Field(label='主页', widget=sf.TextWidget(attrs={'size':30}),)
	comment = sf.Field(label='评论正文', 
		widget=sf.TextWidget(attrs={'multiline':True, 'cols':50, 'rows':8}),
		help_text = '* 必填')
	postid = sf.Field(label='', hidden=True, 
		widget=sf.TextWidget(attrs={'type':'hidden'}))

	def validate(self):
		if self.request.POST:
			data = self.data
			if not data['author']:
				self.errors['author'] = u'请填写你的称呼。'
				return False
			if not data['email']:
				self.errors['email'] = u'请填写你的电子邮件地址。'
				return False
			if not data['comment']:
				self.errors['comment'] = u'请填写评论的内容。'
				return False
			return True
		return False


